<%@page import="edcom.client.*"%>
<%@page import="edcom.server.*"%>
<%

String registering = request.getParameter("registering");
if("GET" == request.getMethod() && registering != null) response.sendRedirect("registration.jsp");

String usertype = new ServletCookieHandler().getCookieValue("usertype", request);
boolean logged = false;
if(usertype != null) logged = true;

// get them!
String name = "";
String snum = "";
String username = "";
String password = "";
String password2 = "";
String email = "";
String major = "";
String header = "All fields are required.";

String[] errorMessages = new String[8]; for(int x = 0; x < 8; x++) errorMessages[x] = "";

String passwordMatchMessage = "";

if(registering != null){
	AddStudentView view = new AddStudentView();
	
	name = request.getParameter("name");
	snum = request.getParameter("snum");
	username = request.getParameter("username");
	password = request.getParameter("password");
	email = request.getParameter("email");
	major = request.getParameter("major");
	
	errorMessages = view.requestAddStudent(name, snum, username, password, email, major);
	
	if((errorMessages[Student.sqlStatus] == "") && (errorMessages[Student.generalError]) == ""){
		session.setAttribute("registered", true);
		response.sendRedirect("registrationSuccess.jsp");
	}
	if(errorMessages[Student.name].isEmpty() && errorMessages[Student.studentNumber].isEmpty() &&
			errorMessages[Student.username].isEmpty() && errorMessages[Student.password].isEmpty() &&
			errorMessages[Student.email].isEmpty() && errorMessages[Student.major].isEmpty())
		header = "We can't register you possibly because of the following:<br/>\n\n+ Your student number " + 
		"is already used<br/>\n+ The username you entered for your account is already used by someone else<br/>\n" +
		"+ The email you entered is already used by another account<br/>\n+ You're already registered<br/>" +
		"If none of these cases apply, please contact the system administrator.";
}
else{
	// NO OPERATION
}

%>
<%@ page import="edcom.server.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    
    <head>
        <title>edcom rules</title>
		<link rel="stylesheet" href="standard.css" type="text/css" />
        <script language="javascript" src="edcom.Base/edcom.Base.nocache.js"></script>
    </head>
    
	<body>

		<div id = "banner_top"><center><img src="images/bannertest9.png" id="bannerimg"></center></div>
		
		<div id="content">
		<div id="content_resize">
		
			<div class="sidebar">
			
				<div id = "login_space">
					<div class="t"><div class="b"><div class="l"><div class="r"><div class="bl"><div class="br"><div class="tl"><div class="tr">
					<div id="logBox" style=""></div>
					</div></div></div></div></div></div></div></div>
				</div>
				
				<div id = "sitemap_space">
					<div class="t"><div class="b"><div class="l"><div class="r"><div class="bl"><div class="br"><div class="tl"><div class="tr">
					<div id="sites" style="">
<%@ include file="sitemap_contents.html" %>
					</div>
					</div></div></div></div></div></div></div></div>
				</div>
				
				<div id = "link_space">
					<div class="t"><div class="b"><div class="l"><div class="r"><div class="bl"><div class="br"><div class="tl"><div class="tr">
					<div id="links" style="">
<%@ include file="links_contents.html" %>
					</div>
					</div></div></div></div></div></div></div></div>
				</div>
			
			</div>
			
			<div id = "general">
				<div class="article">
					<hr>
					<h1>Registration</h1>
					<hr>
<% if(logged) { %> <!-- <% } %> 
<%= header %><br/><br/>
<form action="registration.jsp" method="post"> 
<code>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: <input type="text" name="name" value="<%= name %>"/> <%= errorMessages[Student.name] %><br/>
	&nbsp;Student Number: <input type="text" name="snum" value="<%= snum %>"/> <%= errorMessages[Student.studentNumber] %><br/>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Username: <input type="text" name="username" value="<%= username %>"/> <%= errorMessages[Student.username] %><br/>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password: <input type="password" name="password" value="<%= password %>"/> <%= errorMessages[Student.password] %><br/>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E-mail: <input type="text" name="email" value="<%= email %>"/> <%= errorMessages[Student.email] %><br/>
	&nbsp;Course &amp; Major: <input type="text" name="major" value="<%= major %>"/> <%= errorMessages[Student.major] %><br/>
	<input type="hidden" value="registering" name="registering" />
</code><br/>
<input type="submit" value="Register" />
</form><form action="index.jsp" method="post"><input type="submit" value="Cancel" /></form><% if(!logged){ %> <!-- <% } %> --><%   
if(logged){ %>							
You can't register if you're already logged in.<br/><br/>
<%
} %>
				</div>
			</div>
			
		</div>
		</div>
	
		<div id = "banner_bottom">
			<center>
<%@ include file="banner_bottom_contents.html" %>
			</center>
		</div>   

	<div id="clr"></div>

	</body>

</html>
